<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.pojo.basic.ACCN" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/default.jsp"  %>

<%
	List<ACCN> accns = (List<ACCN>)request.getAttribute("accns");
	Map<String,String> maps = (Map<String,String>)request.getAttribute("maps");
	String   menus = "";
	if(accns != null){
		for(ACCN accn : accns){
			String flag = accn.getCLS().equals("0")?"true":"false";
			String href = accn.getCLS().equals("0")?"":"";
			menus = menus + "{id:'"+accn.getACC_NO()+"',text:'"+accn.getACC_NO()+"&nbsp;&nbsp;&nbsp;&nbsp;"+accn.getNAME()+"',href:'"+href+"',leaf:"+flag+"},";
		}
		menus = menus.substring(0,menus.length()-1);
	}
	
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>系統設定【基本資料】</title>
<link rel="stylesheet" href="/Sunlike/extjs/resources/css/ext-all.css" type="text/css"></link>
<link rel="stylesheet" href="/Sunlike/css/toolbar.css" type="text/css"></link>
<link rel="stylesheet" href="/Sunlike/css/common.css" type="text/css"></link>
<script type="text/javascript" src="/Sunlike/extjs/adapter/ext/ext-base-debug.js"></script>
<script type="text/javascript" src="/Sunlike/extjs/ext-all-debug.js"></script>
<style type="text/css">
<!--
a{text-decoration:none;color:black;};
-->
</style>
<script type="text/javascript">
function tab()
{
	var firstActive = true;
	new Ext.TabPanel({
        renderTo: 'tabsdiv',
        activeTab:0,
        frame:true,
        defaults:{autoHeight: true},
        items:[
            {id:'tab-zc',contentEl:'tab-zc-div', title: '資產'},
            {id:'tab-fz',contentEl:'tab-fz-div', title: '負債'},
            {id:'tab-qy',contentEl:'tab-qy-div', title: '權益'},
            {id:'tab-sr',contentEl:'tab-sr-div', title: '收入'},
            {id:'tab-cb',contentEl:'tab-cb-div', title: '成本'},
            {id:'tab-fy',contentEl:'tab-fy-div', title: '費用'},
            {id:'tab-qtsr',contentEl:'tab-qtsr-div', title: '其他收入'},
            {id:'tab-qtkm',contentEl:'tab-qtkm-div', title: '其他科目'}
        ],
        listeners:{
        	tabchange:function(event,tab){
        		if(firstActive){
        			firstActive = false;
        		}else{
        			var obj = Ext.getCmp(tab.getId()+"-tab");
        			if(obj==null){
        				if(tab.getId()=="tab-fz"){
        					ctree(tab.getId()+"-tab",tab.getId()+"-div",<%= maps.get("2") %>);
        				}
        				if(tab.getId()=="tab-qy"){
        					ctree(tab.getId()+"-tab",tab.getId()+"-div",<%= maps.get("3") %>);
        				}
        				if(tab.getId()=="tab-sr"){
        					ctree(tab.getId()+"-tab",tab.getId()+"-div",<%= maps.get("4") %>);
        				}
        				if(tab.getId()=="tab-cb"){
        					ctree(tab.getId()+"-tab",tab.getId()+"-div",<%= maps.get("5") %>);
        				}
        				if(tab.getId()=="tab-fy"){
        					ctree(tab.getId()+"-tab",tab.getId()+"-div",<%= maps.get("8") %>);
        				}
        			}
        		}
        		
        	}
        }
    });

}
Ext.onReady(tab);

function tree(){
	
	var treeLoader = new Ext.tree.TreeLoader({
		dataUrl : "accnAction.set.findACCNDataByAjax.action"
	}); 
	
	treeLoader.on('beforeload',function(treeLoader, node) {
		treeLoader.baseParams = {
		    accn_no_up: ""+node.id,
	        date: new Date()
	    };
	}, this); 
	
	new Ext.tree.TreePanel({
		id:'tab-zc-tab',
		renderTo: 'tab-zc-div',
		animate:true,
		border:false,
		collapsible:false,
		rootVisible:false,
		autoScroll:false,
		autoHeight:true, 
		root: new Ext.tree.AsyncTreeNode({
			expanded: true,
			loader:treeLoader,
			children: [ <%= menus%> ]
		}),
		listeners:{click:function(node,event){
	   		event.stopEvent(); 
	   		if (node.leaf==true) {  
	   		   	
	        }  
	   	}}
	});	  //new Ext.tree.TreePanel
} 
Ext.onReady(tree);

function ctree(id,reader,menus){
	
	var treeLoader = new Ext.tree.TreeLoader({
		dataUrl : "accnAction.set.findACCNDataByAjax.action"
	}); 
	
	treeLoader.on('beforeload',function(treeLoader, node) {
		treeLoader.baseParams = {
		    accn_no_up: ""+node.id,
	        date: new Date()
	    };
	}, this); 
	
	new Ext.tree.TreePanel({
		id:id,
		renderTo: reader,
		animate:true,
		border:false,
		collapsible:false,
		rootVisible:false,
		autoScroll:false,
		autoHeight:true, 
		root: new Ext.tree.AsyncTreeNode({
			expanded: true,
			loader:treeLoader,
			children:menus
		}),
		listeners:{click:function(node,event){
	   		event.stopEvent(); 
	   		if (node.leaf==true) {  
	   		   	
	        }  
	   	}}
	});	  //new Ext.tree.TreePanel
} 

</script>
</head>
<body>
<div id='toolbarspan'></div>

<table width="100%" border="0" align="center">
<tr><td align="center"><SPAN> <b> <font  size="3">系統設定：基本資料：會計科目</font></b></SPAN> </td></tr>
</table>	

<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tbody><tr> 
      <td></td>
	  
      <td><div align="right"><span><img src="/Sunlike/images/arrow_r_r_small.gif" width="9" height="9"><font  style="font-size:14px;">修改紀錄</font>&nbsp;&nbsp;</span></div></td>
    </tr></tbody>
</table>
  
<div id="tabsdiv" ></div>
<div id="tab-zc-div"></div>
<div id="tab-fz-div"></div>
<div id="tab-qy-div"></div>
<div id="tab-sr-div"></div>
<div id="tab-cb-div"></div>
<div id="tab-fy-div"></div>
<div id="tab-qtsr-div"></div>
<div id="tab-qtkm-div"></div>
</body>
</html>